package jdbc_dcc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DBUtil {
	//建立常量存储数据库地址、用户名、密码
	private static final String URL = "jdbc:mysql://127.0.0.1:3306/dcc?useSSL=true";//MySQL在高版本需要指明是否进行SSL连接
	private static final String USER = "root";
	private static final String PASSWORD = "123456";
	
	
	
	public static void main(String[] args) throws Exception{
		//1.加载驱动程序
		Class.forName("com.mysql.jdbc.Driver");
		//2.（通过数据库的地址、用户名、密码）获得数据库的链接
		Connection conn = DriverManager.getConnection(URL,USER,PASSWORD);
		//3.通过数据库的链接操作数据库，实现增删改查
	    Statement stmt = conn.createStatement();
	    ResultSet rs = stmt.executeQuery("select user_name,age from dcc_goddess");
	    
	    while(rs.next()){//rs.next()如果返回true，说明数据库中有数据
	    	System.out.println(rs.getString("user_name")+","+rs.getInt("age"));
	    	
	    }
	}
}
